package com.one.square.oauth.controller;

import com.one.square.core.domain.Result;
import com.one.square.oauth.entity.Token;
import com.one.square.oauth.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.sql.ResultSet;
import java.text.ParseException;
import java.util.List;

/**
 * @author cwm
 * @Description token管理
 * @date 2021/10/28 上午11:42
 * @Version 1.0
 */
@Api(tags = "token管理")
@RestController
@RequestMapping("/token")
@AllArgsConstructor
@Slf4j
public class TokenController {
    private final TokenService tokenService;


    @ApiOperation(value = "获取所有token列表", notes = "获取所有token列表")
    @GetMapping("/list")
    public Result<List<Token>> list() throws ParseException {
        return Result.succeed(tokenService.list());
    }


    @ApiOperation(value = "删除token",notes = "删除token")
    @DeleteMapping("/delete")
    public Result delete(@RequestParam(value = "tokenValue")
                         @ApiParam(name = "token值", value = "tokenValue", required = true)
                                 String tokenValue) throws ParseException {
        tokenService.delete(tokenValue);
        return Result.succeed("操作成功");
    }
}
